/*
 * Copyright (c) 2013 哈尔滨亿时代数码科技开发有限公司（www.hrbesd.com）. All rights reserved.
 * 
 * HRBESD PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.esd.ps;

import java.io.UnsupportedEncodingException;
import java.security.GeneralSecurityException;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.mail.MessagingException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.esd.db.model.AlipayInfo;
import com.esd.db.model.InspectionOvertimeRecord;
import com.esd.db.model.RemainingTaskWarning;
import com.esd.db.model.VtdNotice;
import com.esd.db.model.VtdParameter;
import com.esd.db.model.employer;
import com.esd.db.model.manager;
import com.esd.db.model.user;
import com.esd.db.model.worker;
import com.esd.db.model.workerRecord;
import com.esd.db.service.AlipayInfoService;
import com.esd.db.service.EmployerService;
import com.esd.db.service.InspectionOvertimeRecordService;
import com.esd.db.service.InspectorMarkTimeRecordService;
import com.esd.db.service.ManagerService;
import com.esd.db.service.RemainingTaskWarningService;
import com.esd.db.service.SalaryService;
import com.esd.db.service.TaskService;
import com.esd.db.service.UserService;
import com.esd.db.service.VtdNoticeService;
import com.esd.db.service.VtdParameterService;
import com.esd.db.service.WorkerRecordService;
import com.esd.db.service.WorkerService;
import com.esd.ps.model.WorkerRecordTrans;
import com.esd.ps.util.RemainingTaskWarningMailSender;


/**
 * 管理员管理worker
 * 
 * @author chen
 * 
 */
@Controller
@RequestMapping("/security")
public class ManagerController {
	private static final Logger logger = LoggerFactory.getLogger(ManagerController.class);
	@Autowired
	private UserService userService;
	@Autowired
	private EmployerService employerService;
	@Autowired
	private WorkerService workerService;
	@Autowired
	private WorkerRecordService workerRecordService;
	@Autowired
	private ManagerService managerService;
	@Autowired
	private SalaryService salaryService;
	@Autowired
	private VtdParameterService paramService;
	@Autowired
	private InspectionOvertimeRecordService iorService;
	@Autowired
	private AlipayInfoService alipayInfoService;
	@Autowired
	private VtdNoticeService noticeService;
	@Autowired
	private TaskService taskService;
	@Autowired
	private RemainingTaskWarningService rtwService;
	@Autowired
	InspectorMarkTimeRecordService imtrService;
	
	@Value("${MSG_UNUPLOAD}")
	private String MSG_UNUPLOAD;

	/**
	 * 修改成功
	 */
	@Value("${MSG_UPDATE_SUCCESS}")
	private String MSG_UPDATE_SUCCESS;
	/**
	 * 修改失败
	 */
	@Value("${MSG_UPDATE_ERROR}")
	private String MSG_UPDATE_ERROR;
	/**
	 * 已超时
	 */
	@Value("${MSG_TIME_OUT}")
	private String MSG_TIME_OUT;
	/**
	 * 未审核
	 */
	@Value("${MSG_UNAUDIT}")
	private String MSG_UNAUDIT;
	/**
	 * 不合格
	 */
	@Value("${MSG_UNQUALIFY}")
	private String MSG_UNQUALIFY;
	/**
	 * 合格
	 */
	@Value("${MSG_QUALIFY}")
	private String MSG_QUALIFY;
	/**
	 * 放弃
	 */
	@Value("${MSG_GIVEUP}")
	private String MSG_GIVEUP;
	/**
	 * 已上传
	 */
	@Value("${MSG_UPLOADED}")
	private String MSG_UPLOADED;

	/**
	 * 登录管理员页
	 * 
	 * @param loginrName
	 * @return
	 */
	@RequestMapping(value = "/manager", method = RequestMethod.GET)
	public ModelAndView managerGet() {
		return new ModelAndView("manager/manager");
	}

	/**
	 * 返回user list
	 * 
	 * @param userNameCondition
	 * @param userType
	 * @param page
	 * @param year
	 * @param month
	 * @param taskUpload
	 * @return
	 */
	@RequestMapping(value = "/manager", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> managerPost(String userNameCondition, int userType, int page, String beginDate, String endDate, 
			int taskUpload, int dateType, int alipayEnabled) {
		logger.debug("userType:{},page:{},userNameCondition:{},year:{},month:{}", userType, page, userNameCondition, beginDate, endDate);
		Map<String, Object> map = new HashMap<String, Object>();
		// SimpleDateFormat sdf = new
		// SimpleDateFormat(Constants.DATETIME_FORMAT);
		int totlePage = Constants.ZERO;
		List<Map<String, Object>> list = workerService.getLikeRealName(userNameCondition, page, Constants.ROW, alipayEnabled);

		map.clear();
		int totle = workerService.getCountLikeRealname(userNameCondition,alipayEnabled);
		totlePage = (int) Math.ceil((double) totle / (double) Constants.ROW);
		map.put(Constants.LIST, list);
		map.put(Constants.TOTLE, totle);
		map.put(Constants.TOTLE_PAGE, totlePage);

		return map;
	}

	/**
	 * 工资列表
	 * 
	 * @param userNameCondition
	 * @param userType
	 * @param page
	 * @param beginDate
	 * @param endDate
	 * @param taskUpload
	 * @param dateType
	 * @param payOffType
	 *            0:未结 1:已结 2 常规
	 * @return
	 */
	@RequestMapping(value = "/workerSalary", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> workerSalaryPost(String userNameCondition, int page, String beginDate, String endDate, int dateType, int salaryLine, int payOffType, String workGroupCode) {
		logger.debug("page:{},userNameCondition:{},year:{},month:{},dateType:{}", page, userNameCondition, beginDate, endDate, dateType);
		int pre = (int) System.currentTimeMillis();
		Map<String, Object> map = new HashMap<String, Object>();
		// SimpleDateFormat sdf = new
		// SimpleDateFormat(Constants.DATETIME_FORMAT);
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		int totlePage = Constants.ZERO;
		List<Map<String, Object>> salaryList = salaryService.getSalary(dateType, page, Constants.ROW, beginDate, endDate, userNameCondition, salaryLine, payOffType, workGroupCode);
		if (salaryList == null) {
			map.put(Constants.LIST, "");
			return map;
		}
		// int pre1 = (int) System.currentTimeMillis();
		// logger.debug("userList:{}",(pre1 - pre));
//		manager manager = managerService.selectByPrimaryKey(1);
//		String wgs = paramService.selectRemarksByParamVlaueAndParamType(workGroupCode, "workGroup");
		DecimalFormat df = new DecimalFormat("#");
		Double d = 0.00;
		for (Iterator<Map<String, Object>> iterator = salaryList.iterator(); iterator.hasNext();) {
			Map<String, Object> map2 = (Map<String, Object>) iterator.next();
			if (map2.get("markTime") == null) {
				map2.put("taskMarkTimeMonth", 0.00);
				map2.put("salary", 0);
			} else {
				d = Double.parseDouble(map2.get("markTime").toString());
				if (d < 0) {
					map2.put("taskMarkTimeMonth", -d/3600);
					map2.put("sec", Math.round(-d));
				} else {
					map2.put("taskMarkTimeMonth", d/3600);
					map2.put("sec", Math.round(d));
				}
//				map2.put("salary", df.format(d * manager.getSalary() / 3600));
//				map2.put("salary", df.format(d * Double.parseDouble(wgs) / 3600));
				map2.put("salary", Math.round(Double.parseDouble(map2.get("salaryValue").toString())));
				//获取计算工资节点  
				int salaryCountTiming = 0;
				List<VtdParameter> outsourcerCodeList = paramService.selectParamByType(Constants.OUTSOURCER_CODES);  //外包商组代码  数据库中只存一条信息  	
				VtdParameter param = outsourcerCodeList.get(0);
		    	String[] outsourcerCodes = param.getParamValue().split(",");
		    	boolean flag = true;
			    for (int i = 0; i < outsourcerCodes.length; i++) {
					if (workGroupCode.equals(outsourcerCodes[i])) {
						flag = false;  //审核的是外包工作者
					}
				}
				List<VtdParameter> paramList = null;
				if(flag){
					paramList = paramService.selectParamByType(Constants.SALARY_COUNT_TIMING);//查询结算设置用的参数 只有一条数据   自营
				}else{
					paramList = paramService.selectParamByType(Constants.OUTSOURCER_SALARY_COUNT_TIMING);//查询外包结算设置用的参数 只有一条数据  外包
				}
				if(!paramList.isEmpty()){
					VtdParameter vp = paramList.get(0);
					salaryCountTiming = Integer.parseInt(vp.getParamValue());
				}
				//获取一次性成功率
				int workerId = Integer.parseInt(map2.get("workerId").toString());
				Map<String, Object> result = workerRecordService.getOneTimeSuccessRate(workerId, beginDate, endDate, dateType, salaryCountTiming);
				map2.putAll(result);
				//获取一层和三层任务的工资数
				List<Map<String, Object>> oneAndThree = salaryService.getSalaryOfOneLayerAndThreelayerByWorkerId(workerId, dateType, beginDate, endDate, payOffType);
				for (Map<String, Object> m : oneAndThree) {
					if(Integer.parseInt(m.get("taskType").toString())==1){
						map2.put("oneLayerSalary", m.get("salary").toString());
					}else{
						map2.put("threeLayerSalary", m.get("salary").toString());
					}
				}
			}
			double oneLayerSubsidyPercent = paramService.getBackup2ByParamValueAndParamType(workGroupCode,Constants.WORK_GROUP);
			map2.put("oneLayerSubsidyPercent", oneLayerSubsidyPercent);
			list.add(map2);
		}
		map.clear();
		// int pre11 = (int) System.currentTimeMillis();
		int totle = salaryService.getSalary100Count(dateType, beginDate, endDate, userNameCondition, salaryLine, payOffType, workGroupCode);
		// int pre12 = (int) System.currentTimeMillis();
		// logger.debug("totle:{}",(pre12 - pre11));
		totlePage = (int) Math.ceil((double) totle / (double) Constants.ROW);
		map.put(Constants.LIST, list);
		map.put(Constants.TOTLE, totle);
		map.put(Constants.TOTLE_PAGE, totlePage);
		return map;
	}
	/**
	 * 获得薪金
	 * 
	 * @param workerId
	 * */
	@RequestMapping(value = "/salaryByWorkerId",method = RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> salaryByWorkerId(int workerId){
		Map<String, Object> map = new HashMap<String, Object>();
		List<worker> listw = workerService.getWorkerIdByUpdateId(workerId);
		if(listw == null){
		   return null;	
		}
		for (Iterator<worker> iterator = listw.iterator(); iterator.hasNext();) {
			worker worker = (worker) iterator.next();
			worker.getWorkerId();
		}
		//salaryService.getSalary(dateType, page, row, beginDate, endDate, realName, salaryLine, payOffType)
		return map;	
	}
	/**
	 * 等级列表
	 * 
	 * @param userNameCondition
	 * @param page
	 * @param userLvl
	 * @return
	 */
	@RequestMapping(value = "/workerLvl", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> workerLvlPost(String userNameCondition, int page, int userLvl) {
		Map<String, Object> map = new HashMap<String, Object>();
		int totlePage = Constants.ZERO;
		List<Map<String, Object>> list = workerService.getWorkerLvl(userNameCondition, userLvl, page, Constants.ROW);
		if (list == null) {
			map.put(Constants.LIST, "");
			return map;
		}
		map.clear();
		int totle = workerService.getWorkerLvlCount(userNameCondition, userLvl);
		totlePage = (int) Math.ceil((double) totle / (double) Constants.ROW);
		map.put(Constants.LIST, list);
		map.put(Constants.TOTLE, totle);
		map.put(Constants.TOTLE_PAGE, totlePage);
		return map;
	}

	/**
	 * 结算
	 * 
	 * @param userNameCondition
	 * @param beginDate
	 * @param endDate
	 * @param dateType
	 * @param salaryLine
	 * @return
	 */
	@RequestMapping(value = "/payOff", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> payOffPost(String workerIds, String beginDate, String endDate, int dateType) {
		Map<String, Object> map = new HashMap<String, Object>();
		// String str[] = endDate.split("-");
		// int month = Integer.parseInt(str[1]);
		// int year = Integer.parseInt(str[0]);
		// if(month == 1){
		// year = year - 1;
		// month = 12;
		// }else{
		// month = month - 1;
		// }
		// String month1 = "00" + month;
		// month1 = month1.substring((month1.length() - 2),month1.length());
		// String timer = year + "-" + month1 + "-" +"10";

		String workerId[] = workerIds.split("/");
		int replay = salaryService.insertPayOffInfor1(dateType, beginDate, endDate, workerId, endDate);
		map.put(Constants.REPLAY, replay);
		return map;
	}
	/**
	 * 
	 * @param workerIds
	 * @param userLvl
	 * @return
	 */
	@RequestMapping(value = "/updateWorkerLvl", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> updateWorkerLvlPost(String workerIds,int userLvl) {
		Map<String, Object> map = new HashMap<String, Object>();
		String workerId[] = workerIds.split("/");
		int replay = userService.updateWorkerLvl(workerId,userLvl);
		map.put(Constants.REPLAY, replay);
		return map;
	}

	/**
	 * 获得语音标注总和
	 * 
	 * @param userNameCondition
	 * 
	 * 
	 * @param beginDate
	 * @param endDate
	 * @param taskUpload
	 * @param dateType
	 * @return
	 */
	@RequestMapping(value = "/getMarkTimeTotle", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> getMarkTimeTotlePost(String userNameCondition, String beginDate, String endDate, int taskUpload, int dateType) {
		Map<String, Object> map = new HashMap<String, Object>();
		Double taskMarkTimeMonthTotle = 0.00;
		Double aduitingMarkTimeMonthTotle = 0.00;
		if (taskUpload > 0) {
			taskMarkTimeMonthTotle = workerRecordService.getTaskMarkTimeMonthByWorkerIdAndMonth(0, beginDate, endDate, userNameCondition, 1, 1, dateType);
			aduitingMarkTimeMonthTotle = workerRecordService.getTaskMarkTimeMonthByWorkerIdAndMonth(0, beginDate, endDate, userNameCondition, 0, 1, dateType);
		}
		if (taskMarkTimeMonthTotle == null) {
			map.put("taskMarkTimeMonthTotle", 0);
		} else {
			map.put("taskMarkTimeMonthTotle", taskMarkTimeMonthTotle);
		}
		if (aduitingMarkTimeMonthTotle == null) {
			map.put("aduitingMarkTimeMonthTotle", 0);
		} else {
			map.put("aduitingMarkTimeMonthTotle", aduitingMarkTimeMonthTotle);
		}
		manager manager = managerService.selectByPrimaryKey(1);
		if (manager.getSalary() > 0) {
			map.put("salary", manager.getSalary());
		} else {
			map.put("salary", 0.00);
		}
		return map;
	}

	/**
	 * 工资单合计
	 * 
	 * @param userNameCondition
	 * @param beginDate
	 * @param endDate
	 * @param dateType
	 * @return
	 */
	@RequestMapping(value = "/getSumSalary", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> getSumSalaryPost(String userNameCondition, String beginDate, String endDate, int dateType, int salaryLine, int payOffType) {
		Map<String, Object> map = new HashMap<String, Object>();
////		Double sumSalary = salaryService.getSUMSalary(dateType, beginDate, endDate, userNameCondition, salaryLine, payOffType);
////		if (sumSalary == null) {
////			map.put("sumSalary", 0);
////		} else {
////			if (sumSalary < 0) {
////				map.put("sumSalary", -sumSalary);
////			} else {
////				map.put("sumSalary", sumSalary);
////			}
////		}
////		manager manager = managerService.selectByPrimaryKey(1);
////		if (manager.getSalary() > 0) {
////			map.put("salary", manager.getSalary());
////		} else {
////			map.put("salary", 0.00);
////		}
//		//查询工作组代码和标注时间
//		List<Map<String,Object>> workGroupAndSumMarkTimeList = salaryService.getWorkGroupAndSumMarkTime(dateType, beginDate, endDate, userNameCondition, salaryLine, payOffType);
//		//将标注时间和工资信息组织好返回给页面
//		double markTime = 0.00;
//		double totleSalary = 0.00;
//		if(!workGroupAndSumMarkTimeList.isEmpty()){
//			for (int i = 0; i < workGroupAndSumMarkTimeList.size(); i++) {
//				Map<String,Object> tempMap = workGroupAndSumMarkTimeList.get(i);
//				String workGroupSalary = paramService.selectRemarksByParamVlaueAndParamType(tempMap.get("workGroup").toString(),"workGroup");
//				totleSalary = totleSalary+(Double.parseDouble(tempMap.get("markTime").toString())*Double.parseDouble(workGroupSalary)/3600);
//				markTime = markTime + Double.parseDouble(tempMap.get("markTime").toString());
//			}		
//		}
//		//标注时间单位 是小时     保留两位小数
//		map.put("markTime", Math.round(markTime/3600*100)*0.01d);
//		map.put("salary", Math.round(totleSalary*100)*0.01d);
		
		//总数从新添加的静态工资字段中直接取出相加
		Map<String,Object> totleHoursAndtotleMoney = salaryService.getTotleHoursAndTotleMoney(dateType, beginDate, endDate, userNameCondition, salaryLine, payOffType);
		map.put("markTime", (Math.round(Double.parseDouble(totleHoursAndtotleMoney.get("markTime").toString())/3600*100))*0.01d);
		map.put("salary", Math.round(Double.parseDouble(totleHoursAndtotleMoney.get("salaryValue").toString())));
		return map;
	}

	/**
	 * 获得标注时间通过userId
	 * 
	 * @param userId
	 * @param userNameCondition
	 * @param userType
	 * @param page
	 * @param beginDate
	 * @param endDate
	 * @param taskUpload
	 * @param dateType
	 * @return
	 */
	@RequestMapping(value = "/getMarkTime", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> getMarkTimePost(int userId, String userNameCondition, int userType, int page, String beginDate, String endDate, int taskUpload, int dateType) {
		Map<String, Object> map = new HashMap<String, Object>();
		double waitMarkTime = 0.00;
		int workerId = workerService.getWorkerIdByUserId(userId);
		Double markTime = workerRecordService.getTaskMarkTimeMonthByWorkerIdAndMonth(workerId, beginDate, endDate, userNameCondition, 1, 1, dateType);
		if (markTime == null) {
			map.put("markTime", 0);
		} else {
			map.put("markTime", markTime);
		}
		// 下载
		int downCount = workerRecordService.getdownCountByWorkerIdAndDate(workerId, dateType, beginDate, endDate);
		// 放弃
		int giveUpCount = workerRecordService.getCountByWorkerIdAndDate(workerId, dateType, beginDate, endDate, 3, 0);
		// 合格
		int finishCount = workerRecordService.getCountByWorkerIdAndDate(workerId, dateType, beginDate, endDate, 1, 1);
		// 过时
		int oldCount = workerRecordService.getCountByWorkerIdAndDate(workerId, dateType, beginDate, endDate, 2, 0);
		// 待上传
		int waitingUpLoadCount = workerRecordService.getCountByWorkerIdAndDate(workerId, dateType, beginDate, endDate, 0, 0);
		// 待审核
		int waitingEffective = workerRecordService.getCountByWorkerIdAndDate(workerId, dateType, beginDate, endDate, 1, 0);
		// 待审核标注时间
		try {
			waitMarkTime = workerRecordService.getTaskMarkTimeMonthByWorkerIdAndMonth(workerId, beginDate, endDate, userNameCondition, 0, 1, dateType);
		} catch (NullPointerException n) {
			waitMarkTime = 0.00;
		}
		// 查询推荐成功的人数
		int referralNum = userService.getReferralNumByUserId(userId);
		map.put("downCount", downCount);
		map.put("giveUpCount", giveUpCount);
		map.put("finishCount", finishCount);
		map.put("oldCount", oldCount);
		map.put("unUpLoadCount", waitingUpLoadCount);
		map.put("waitingEffectiveCount", waitingEffective);
		map.put("waitMarkTime", waitMarkTime);
		map.put("referralNum", referralNum);
		return map;
	}

	/**
	 * 得到manager
	 * 
	 * @return
	 */
	@RequestMapping(value = "/getManager", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> getManagerPost() {
		Map<String, Object> map = new HashMap<String, Object>();
		manager manager = managerService.selectByPrimaryKey(1);
		map.put("manager", manager);
		return map;
	}

	/**
	 * 修改累计下载数,单次下载数,有效文件大小
	 * 
	 * @param downCount
	 * @param downMaxCount
	 * @param fileSize
	 * @return
	 */
	@RequestMapping(value = "/updateCount", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> updateCountPost(int downCount, int downMaxCount, int fileSize, double salary) {
		Map<String, Object> map = new HashMap<String, Object>();
		manager manager = new manager();
		manager.setManagerId(1);
		manager.setDownCount(downCount);
		manager.setDownMaxCount(downMaxCount);
		manager.setFileSize(fileSize);
		manager.setSalary(salary);
		int m = managerService.updateByPrimaryKeySelective(manager);
		String workerDownCount = String.valueOf(downMaxCount)+"/"+String.valueOf(downCount);
		managerService.updateAllWorkerDownCount(workerDownCount);
		map.clear();
		if (m == 1) {
			map.put(Constants.REPLAY, 1);
			map.put(Constants.MESSAGE, MSG_UPDATE_SUCCESS);
		} else {
			map.put(Constants.REPLAY, 0);
			map.put(Constants.MESSAGE, MSG_UPDATE_ERROR);
		}
		return map;
	}

	/**
	 * 更新个人的下载量
	 * 
	 * @param downCount
	 * @param userId
	 * @return
	 */
	@RequestMapping(value = "/updateDownCount", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> updateDownCountPost(String downCount, int userId) {
		Map<String, Object> map = new HashMap<String, Object>();
		int workerId = workerService.getWorkerIdByUserId(userId);
		worker worker = new worker();
		worker.setWorkerId(workerId);
		if (downCount.equals("0")) {
			worker.setDownCount(null);
		} else {
			worker.setDownCount(downCount);
		}
		workerService.updateByPrimaryKeySelective(worker);
		map.put(Constants.REPLAY, 1);
		return map;
	}

	/**
	 * 工作者工作信息
	 * 
	 * @param userId
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/workerDetail", method = RequestMethod.GET)
	public ModelAndView workerDetailGET(int userId, HttpServletRequest request) {
		Map<String, Object> model = new HashMap<>();
		try {
			String username = new String(request.getParameter("username").getBytes("iso-8859-1"), "utf-8");
			model.clear();
			model.put(Constants.USER_ID, userId);
			model.put(Constants.CHOOSEUSERNAME, username);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return new ModelAndView("manager/workerDetail", Constants.MODEL, model);

	}

	/**
	 * 工作者工作信息
	 * 
	 * @param userId
	 * @param userType
	 * @param page
	 * @param month
	 * @param statu
	 * @param taskNameCondition
	 * @return
	 */
	@RequestMapping(value = "/workerDetail", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> workerDetailPOST(HttpSession session, int userId, int userType, int page, String beginDate, String endDate, int statu, String taskNameCondition, int dateType) {
		Map<String, Object> map = new HashMap<>();
		if (userType == 2) {
			employer employer = employerService.getEmployerByUserId(userId);
			map.clear();
			map.put(Constants.USER_DETAIL, employer);
		}
		if(taskNameCondition.indexOf("_")>-1){
			taskNameCondition = taskNameCondition.replaceAll("_", "\\\\_");
		}
		if (userType == 4) {
			int workerId = workerService.getWorkerIdByUserId(userId);
			int totle = workerRecordService.getAllCountByWorkerId(workerId, statu, beginDate, endDate, taskNameCondition, dateType);
			Double taskMarkTimeMonth = workerRecordService.getTaskMarkTimeMonthByWorkerIdAndMonth(workerId, beginDate, endDate, taskNameCondition, 1, 1, dateType);
			List<workerRecord> workerRecordList = workerRecordService.getAllByWorkerId(workerId, 1, statu, beginDate, endDate, taskNameCondition, page, Constants.ROW, dateType);
			List<WorkerRecordTrans> list = new ArrayList<>();
			SimpleDateFormat sdf = new SimpleDateFormat(Constants.DATETIME_FORMAT);
			for (Iterator<workerRecord> iterator = workerRecordList.iterator(); iterator.hasNext();) {
				workerRecord workerRecord = (workerRecord) iterator.next();
				WorkerRecordTrans workerRecordTrans = new WorkerRecordTrans();

				workerRecordTrans.setTaskDownTime(sdf.format(workerRecord.getTaskDownTime()));
				if (workerRecord.getTaskEffective() == 0) {
					workerRecordTrans.setTaskEffective(MSG_UNAUDIT);
				} else if (workerRecord.getTaskEffective() == 1) {
					workerRecordTrans.setTaskEffective(MSG_QUALIFY);
				} else if (workerRecord.getTaskEffective() == 2) {
					workerRecordTrans.setTaskEffective(MSG_UNQUALIFY);
				} else if (workerRecord.getTaskEffective() == 3||workerRecord.getTaskEffective()==4
						||workerRecord.getTaskEffective()==5||workerRecord.getTaskEffective()==6) {
					workerRecordTrans.setTaskEffective("审核中");
				}
				if (workerRecord.getTaskMarkTime() == null) {
					workerRecordTrans.setTaskMarkTime(0.00);
				} else {
					workerRecordTrans.setTaskMarkTime(workerRecord.getTaskMarkTime());
				}
				workerRecordTrans.setTaskName(workerRecord.getTaskName().substring(0, workerRecord.getTaskName().lastIndexOf("@")));
				if (workerRecord.getTaskStatu() == 1) {
					workerRecordTrans.setTaskStatu(MSG_UPLOADED);
				} else if (workerRecord.getTaskStatu() == 0) {
					workerRecordTrans.setTaskStatu(MSG_UNUPLOAD);
				} else if (workerRecord.getTaskStatu() == 2) {
					workerRecordTrans.setTaskStatu(MSG_TIME_OUT);
				} else if (workerRecord.getTaskStatu() == 3) {
					workerRecordTrans.setTaskStatu("已放弃");
				} else if (workerRecord.getTaskStatu() == 4) {
					workerRecordTrans.setTaskStatu("被回收");
				}

				if (workerRecord.getTaskUploadTime() == null) {
					workerRecordTrans.setTaskUploadTime(Constants.EMPTY);
				} else {
					workerRecordTrans.setTaskUploadTime(sdf.format(workerRecord.getTaskUploadTime()));
				}

				list.add(workerRecordTrans);
			}

			map.clear();
			int totlePage = (int) Math.ceil((double) totle / (double) Constants.ROW);
			map.put(Constants.LIST, list);
			map.put(Constants.TOTLE, totle);// totleG
			map.put(Constants.TOTLE_PAGE, totlePage);
			if (taskMarkTimeMonth == null) {
				map.put("taskMarkTimeMonth", 0.00);
			} else {
				map.put("taskMarkTimeMonth", taskMarkTimeMonth);
			}
		}
		return map;
	}
	
	
	/**
	 * 转到查看被推荐人列表页面
	 * 
	 * @param userId
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/getViewOfReferrals", method = RequestMethod.GET)
	public ModelAndView getViewOfReferralsGET(int userId, HttpServletRequest request) {
		Map<String, Object> model = new HashMap<>();
		user u = userService.getByPrimaryKey(userId);
//		System.out.println(u.getReferrerId());
		model.clear();
		model.put(Constants.USER_ID, userId);
		model.put(Constants.CHOOSEUSERNAME, u.getUsername());
		model.put("thisUserReferrerId", u.getReferrerId());
		return new ModelAndView("manager/viewOfReferrals", Constants.MODEL, model);

	}

	/**
	 * 查看被推荐人列表
	 * 
	 * @param userId
	 * @return
	 */
	@RequestMapping(value = "/getViewOfReferrals", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> getViewOfReferralsPost(int userId, int page, String referralUsernameCondition,String dateCondition) {
		Map<String, Object> map = new HashMap<String, Object>();
		List<Map<String,Object>> resultList = new ArrayList<Map<String,Object>>();
		//查询被推荐人相关信息
		Map<String, Object> condition = new HashMap<String, Object>();
		condition.put("referrer", userId); //推荐人ID
		condition.put("referralUsername", referralUsernameCondition);//页面查询条件
		int totle = userService.getReferralUsersCount(condition);
		condition.put("begin", ((page - 1) * Constants.ROW)); //分页
		condition.put("end", Constants.ROW);    //分页
		List<user> users = userService.getReferralUsers(condition);
		int totlePage = (int) Math.ceil((double) totle / (double) Constants.ROW);
		map.put(Constants.LIST, users);
		map.put(Constants.TOTLE, totle);// totleG
		map.put(Constants.TOTLE_PAGE, totlePage);
		
		//标注时间
		for (user u : users) {
			worker worker = workerService.getWorkerByUserId(u.getUserId());
			if(worker!=null){
				Map<String,Object> tempMap = salaryService.getSumMarkTimeAndSalaryValueForViewOfReferrals(worker.getWorkerId(), dateCondition);
				Map<String,Object> view = new HashMap<String,Object>();
				view.put("username", u.getUsername());
				view.put("realName", worker.getWorkerRealName());
				view.put("marktime", Double.parseDouble(tempMap.get("markTime").toString())/3600);
				view.put("salaryValue", Math.round(Double.parseDouble(tempMap.get("salaryValue").toString())));
				resultList.add(view);
			}
		}
		map.put(Constants.LIST, resultList);
		return map;
	}
	
	/**
	 * 添加被推荐人
	 * 
	 * @param userId
	 * @return
	 */
	@RequestMapping(value = "/addReferral", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> addReferralPost(int useridToAdd, int useridToUpdate) {
		Map<String, Object> map = new HashMap<String, Object>();
		System.out.println(useridToAdd);
		System.out.println(useridToUpdate);
		int num = userService.updateReferrerIdByUserId(useridToUpdate,useridToAdd);
		int flag;
		if(num==1){
			flag = 1;
		}else{
			flag = 0;
		}
		map.put(Constants.MESSAGE, flag);
		return map;
	}
	
	/**
	 * 工作组列表
	 * 
	 * @param workGroupNameCondition
	 * @param page
	 * @param beginDate
	 * @param endDate
	 * @param dateType
	 * @return
	 */
	@RequestMapping(value = "/workGroupList", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> workGroupListPost(String workGroupNameCondition, int page, String beginDate, String endDate, int dateType) {
//		int pre = (int) System.currentTimeMillis();
		Map<String, Object> map = new HashMap<String, Object>();
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		int totlePage = Constants.ZERO;
		List<Map<String, Object>> workGroupList = salaryService.getWorkGroupCodeAndSumMarkTimeList(dateType, page, Constants.ROW, beginDate, endDate, workGroupNameCondition);
		if (workGroupList == null) {
			map.put(Constants.LIST, "");
			return map;
		}
//		manager manager = managerService.selectByPrimaryKey(1);
//		DecimalFormat df = new DecimalFormat("#");
		Double d = 0.00;
		for (Map<String, Object> map2 : workGroupList) {
			if (map2.get("markTime") == null) {
				map2.put("taskMarkTimeMonth", 0.00);
				map2.put("salary", 0);
			} else {
				d = Double.parseDouble(map2.get("markTime").toString());
//				double workGroupSalary = Double.parseDouble(map2.get("workGroupSalary").toString());
				if (d < 0) {
					map2.put("taskMarkTimeMonth", -d);
				} else {
					map2.put("taskMarkTimeMonth", d);
				}
//				map2.put("salary", df.format(d * manager.getSalary() / 3600));
//				map2.put("salary", df.format(d * workGroupSalary / 3600));
				map2.put("salary",Math.round(Double.parseDouble(map2.get("salaryValue").toString())));
			}
			list.add(map2);
		}
		map.clear();
		int totle = salaryService.getWorkGroupListCount(dateType, beginDate, endDate, workGroupNameCondition);
		totlePage = (int) Math.ceil((double) totle / (double) Constants.ROW);
		map.put(Constants.LIST, list);
		map.put(Constants.TOTLE, totle);
		map.put(Constants.TOTLE_PAGE, totlePage);
		return map;
	}
	
	/**
	 * 工作组详细工资列表信息
	 * 
	 * @param userId
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/workGroupSalaryDetails", method = RequestMethod.GET)
	public ModelAndView workGroupSalaryDetailsGET(String workGroupCode, HttpServletRequest request) {
		Map<String, Object> model = new HashMap<>();
		String dateType = request.getParameter("dateType");
		String beginDate = request.getParameter("beginDate");
		String endDate = request.getParameter("endDate");
		try {
			String workGroupName = new String(request.getParameter("workGroupName").getBytes("iso-8859-1"), "utf-8");
			model.clear();
			model.put("workGroupCode", workGroupCode);
			model.put("workGroupName", workGroupName);
			model.put("dateType", dateType);
			model.put("beginDate", beginDate);
			model.put("endDate", endDate);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return new ModelAndView("manager/workGroupSalaryList", Constants.MODEL, model);

	}
	
	/**
	 * 审核信息
	 * @param beginDate
	 * @param endDate
	 * @param dateType
	 * @return
	 */
	@RequestMapping(value = "/inspectionDetail", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> inspectionDetailPost(String beginDate, String endDate, int dateType) {
		Map<String, Object> map = new HashMap<String, Object>();
		//查询工作者完成任务数   workerRecordService   
		int doneNum = workerRecordService.getWorkerDoneTaskNumForInspectionDetail(beginDate,endDate,dateType);
		//查询显示列表  包含了未审核数
		List<Map<String,Object>> list = workerRecordService.getDetailListForInspectionDetail(beginDate,endDate,dateType);
		//下载次数查询
		Map<String,Integer> downCountMap = workerRecordService.getInspDownloadCount(beginDate,endDate,dateType);
		List<Integer> tempList = new ArrayList<Integer>();
		for (Map<String, Object> m : list) {
			tempList.add((int)m.get("taskEffective"));
		}
		//填补查询数据中没有的项目
		if(!tempList.contains(0)){
			Map<String,Object> tempMap = new HashMap<String,Object>();
			tempMap.put("taskNum", 0);
			tempMap.put("inspByUserNum", 0);
			tempMap.put("inspByDayNum", 0);
			tempMap.put("inspByPackageNum", 0);
			tempMap.put("taskEffective", 0);
			list.add(tempMap);
		}
		if(!tempList.contains(3)){
			Map<String,Object> tempMap = new HashMap<String,Object>();
			tempMap.put("taskNum", 0);
			tempMap.put("inspByUserNum", 0);
			tempMap.put("inspByDayNum", 0);
			tempMap.put("inspByPackageNum", 0);
			tempMap.put("taskEffective", 3);
			list.add(tempMap);
		}
		if(!tempList.contains(4)){
			Map<String,Object> tempMap = new HashMap<String,Object>();
			tempMap.put("taskNum", 0);
			tempMap.put("inspByUserNum", 0);
			tempMap.put("inspByDayNum", 0);
			tempMap.put("inspByPackageNum", 0);
			tempMap.put("taskEffective", 4);
			list.add(tempMap);
		}
		if(!tempList.contains(1)){
			Map<String,Object> tempMap = new HashMap<String,Object>();
			tempMap.put("taskNum", 0);
			tempMap.put("inspByUserNum", 0);
			tempMap.put("inspByDayNum", 0);
			tempMap.put("inspByPackageNum", 0);
			tempMap.put("taskEffective", 1);
			list.add(tempMap);
		}
		// List排序  上方代码不全list后顺序不是按照taskEffective的 0 3 4 1排序  所以需要重新排序
		List<Map<String,Object>> sortList = new ArrayList<Map<String,Object>>();
		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < list.size(); j++) {
				if(i==0&&(int)list.get(j).get("taskEffective")==0){
					sortList.add(list.get(j));
				}else if(i==1&&(int)list.get(j).get("taskEffective")==3){
					sortList.add(list.get(j));
				}else if(i==2&&(int)list.get(j).get("taskEffective")==4){
					sortList.add(list.get(j));
				}else if(i==3&&(int)list.get(j).get("taskEffective")==1){
					sortList.add(list.get(j));
				}
			}
		}
		map.clear();
		map.put("doneNum", doneNum);
		map.put(Constants.LIST, sortList);
		map.put("downCountMap", downCountMap);
		return map;
	}
	
	
	/**
	 * 获取结算设置显示信息   以后如果有更多的内容这个方法还会继续修改
	 */
	@RequestMapping(value = "/querySalarySettings", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> querySalarySettingsPost() {
		Map<String, Object> map = new HashMap<String, Object>();

		List<VtdParameter> paramList = paramService.selectParamByType(Constants.SALARY_COUNT_TIMING);//查询结算设置用的参数 只有一条数据
		List<VtdParameter> outsourcerSalaryCountTimingList = paramService.selectParamByType(Constants.OUTSOURCER_SALARY_COUNT_TIMING);//查询结算设置用的参数 只有一条数据
		int salaryCountTimingValue = 0;
		int outsourcerSalaryCountTimingValue = 0;
		if(!paramList.isEmpty()){
			VtdParameter vp = paramList.get(0);
			salaryCountTimingValue = Integer.parseInt(vp.getParamValue());
		}
		if(!outsourcerSalaryCountTimingList.isEmpty()){
			VtdParameter vp = outsourcerSalaryCountTimingList.get(0);
			outsourcerSalaryCountTimingValue = Integer.parseInt(vp.getParamValue());
		}
		map.put("sctValue", salaryCountTimingValue);
		map.put("osctValue", outsourcerSalaryCountTimingValue);
		return map;
	}	
	
	
	/**
	 * 更新工资结算节点 
	 */
	@RequestMapping(value = "/updateSalarySettings", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> updateSalarySettingsPost(int salaryCountTiming, int updateType) {
		Map<String, Object> map = new HashMap<String, Object>();
		//查询外包工作组的代码
		List<VtdParameter> outsourcerCodeList = paramService.selectParamByType(Constants.OUTSOURCER_CODES);  //外包商组代码  数据库中只存一条信息  	
    	VtdParameter param = outsourcerCodeList.get(0);
    	String[] outsourcerCodes = param.getParamValue().split(",");
		List<VtdParameter> paramList = null;
		if(updateType == 1){// updateType 1是自营平台   2是外包
			paramList = paramService.selectParamByType(Constants.SALARY_COUNT_TIMING);//查询结算设置用的参数 只有一条数据
		}else{
			paramList = paramService.selectParamByType(Constants.OUTSOURCER_SALARY_COUNT_TIMING);//查询外包结算设置用的参数 只有一条数据
		}
		int updateCount=0;
		int remainNum = 0;  //剩余未审核任务数
		if(!paramList.isEmpty()){
			VtdParameter vp = paramList.get(0);
			// 限制条件   1初审合格  2巡审合格  3包审合格
			int sct_old = Integer.parseInt(vp.getParamValue());
			if(salaryCountTiming<sct_old){
				//原结算时间是在包审审核通过后结算  向前修改  可调整到巡审和初审需要分别校验是否有剩余数据
				if(sct_old==3){ 
					if(salaryCountTiming==2){ //调整至巡审合格之后结算   只要检查包审核是否有未审核数据
						remainNum = workerRecordService.getUninspectorCountByTaskEffectiveAndGroupCodes(4,outsourcerCodes,updateType);
					}else if(salaryCountTiming==1){ //调整至初审合格之后结算   需要检查巡审和包审核是否有未审核数据
						int tempNum1 = 0;
						tempNum1 = workerRecordService.getUninspectorCountByTaskEffectiveAndGroupCodes(4,outsourcerCodes,updateType);
						int tempNum2 = 0;
						tempNum2 = workerRecordService.getUninspectorCountByTaskEffectiveAndGroupCodes(3,outsourcerCodes,updateType);
						remainNum = tempNum1+tempNum2;
					}
				}else if(sct_old==2){ //原结算时间是在巡审审核通过后结算  向前修改  可调整到初审  需要校验是否有剩余数据
					remainNum = workerRecordService.getUninspectorCountByTaskEffectiveAndGroupCodes(3,outsourcerCodes,updateType);
				}
			}
			if(remainNum==0){ // 有任务剩余不能更新
				updateCount = paramService.updateParamValueById(vp.getId(), String.valueOf(salaryCountTiming));				
			}else{
				map.put("msg", "工资计算节点调整失败,当前计算节点有未完成审核的任务存在!");
				return map;
			}
		}
		if(updateCount==1){
			map.put("msg", "设置成功");
		}else{
			map.put("msg", "设置失败");
		}
		return map;
	}	
	
    /**
     * 定时器
     * 记录非外包工作者上传48小时候未巡审和外包初审后48小时未进行巡审的任务数
     */
//	@RequestMapping(value = "/sssaaa", method = RequestMethod.GET)  //测试用请求地址
    @Scheduled(cron="0 00 9 * * ?")    
    public void inspOvertimeTaskNumTimer(){
    	logger.error("定时器: 记录工作者已经上传并且超过48小时没有审核的任务数  ERROR是自己定的级别线上应该只显示ERROR的log");
    	long TimeInterval = 172800000;    // 60*60*48*1000  48小时的毫秒数
    	long now = new Date().getTime();  // 程序执行时的时间毫秒数
    	List<VtdParameter> paramList = paramService.selectParamByType(Constants.OUTSOURCER_CODES);  //外包商组代码  数据库中只存一条信息  	
    	VtdParameter param = paramList.get(0);
    	String[] outsourcerCodes = param.getParamValue().split(",");
    	//查询初审未审核任务列表
    	List<Map<String, Object>> list = workerRecordService.findUninspectWorkerRecordForFirstInspection();
    	//找到超过48小时未审核的任务并记录
    	int count = 0;
    	for (Map<String, Object> m : list) {
    		boolean flag = true;
    		String workGroupCode = m.get("workGroupCode").toString();
			for (int i = 0; i < outsourcerCodes.length; i++) {
				if (workGroupCode.equals(outsourcerCodes[i])) {
					flag = false;
				} 
			}
			if (flag) {//普通从上传到初审超过48小时记录
				Date uploadTime = (Date)m.get("uploadTime");
				if((uploadTime.getTime()+TimeInterval) < now){
					count++;
				}
			} 
		}
    	//TODO 需要修改 区分 结算时间超时  没有做活有时间改成跟随时间节点设置自动的
    	//查询数据 根据workgroup区分需要计算超时的时间 
    	List<Map<String,Object>> list1 = workerRecordService.findUninspectWorkerRecordForSecondInspection();
    	int count2 = 0;  //count2外包商计数
    	for (Map<String, Object> m : list1) {
    		boolean outsourcerFlag = false;
    		String workGroupCode = m.get("workGroupCode").toString();
			for (int i = 0; i < outsourcerCodes.length; i++) {
				if (workGroupCode.equals(outsourcerCodes[i])) {
					outsourcerFlag = true;
				} 
			}
			if (outsourcerFlag) {//外包商从初审到巡审超过48小时记录
				Date taskOverTime = (Date)m.get("taskOverTime");
				if((taskOverTime.getTime()+TimeInterval) < now){
					count2++;
				}
			}
		}
    	//将记录添加到超时记录表中
		InspectionOvertimeRecord ior = new InspectionOvertimeRecord();
		ior.setInspectOvertimeNum(count);
		ior.setInspFirstToSecondOvertimeNum(count2);
		ior.setCreateTime(new Date());
		iorService.inspectionOvertimeRecorder(ior);
		
	}
    
    /**
	 * 审核48小时超时信息
	 * @param beginDate
	 * @param endDate
	 * @param dateType
	 * @return
	 */
	@RequestMapping(value = "/queryInspectionOvertimeRecords", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> queryInspectionOvertimeRecordsPost(String beginDate, String endDate, int dateType) {
		Map<String, Object> map = new HashMap<String, Object>();
		SimpleDateFormat sdf = new SimpleDateFormat(Constants.DATETIME_FORMAT);
		List<Map<String, String>> resultList = new ArrayList<Map<String, String>>(); 
		//前台的查询条件
		Map<String,Object> conditions = new HashMap<String, Object>();
		conditions.put("beginDate", beginDate);
		conditions.put("endDate", endDate);
		conditions.put("dateType", dateType);
		//查询显示用list
		List<InspectionOvertimeRecord> list = iorService.queryInspectionOvertimeRecordListByCondition(conditions);
		//处理页面显示用的信息
		if(!list.isEmpty()){
			for (InspectionOvertimeRecord ior : list) {
				Map<String,String> tempMap = new HashMap<String, String>();
				tempMap.put("num1", String.valueOf(ior.getInspectOvertimeNum()));
				tempMap.put("num2", String.valueOf(ior.getInspFirstToSecondOvertimeNum()));
				tempMap.put("createTime", sdf.format(ior.getCreateTime()));
				resultList.add(tempMap);
			}
		}else{
			resultList = null;
		}
		map.put("list", resultList);
		return map;
	}
	
	/**
	 * 工作组管理列表
	 */
	@RequestMapping(value = "/getWorkGroupSettingList", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> getWorkGroupSettingListPost() {
		Map<String, Object> map = new HashMap<String, Object>();
		List<VtdParameter> list = paramService.selectAllParamByType(Constants.WORK_GROUP);
		List<VtdParameter> outsourcerCodeList = paramService.selectParamByType(Constants.OUTSOURCER_CODES);  //外包商组代码  数据库中只存一条信息  	
		map.put("result", list);
		map.put("osCode", outsourcerCodeList.get(0).getParamValue());
		return map;
	}	
	
	/**
	 * 修改工作组工资
	 */
	@RequestMapping(value = "/modifyWorkGroupSalary", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> modifyWorkGroupSalaryPost(String salary, int paramId, int layerNum) {
		Map<String, Object> map = new HashMap<String, Object>();
		VtdParameter param =  paramService.selectParamById(paramId);
		String[] salarys = param.getRemarks().split("/");
		if(layerNum==1){
			salarys[0] = salary;
		}else{
			salarys[1] = salary;
		}
		String salaryFinal = salarys[0]+"/"+salarys[1];
		int count = paramService.updateRemarksById(paramId, salaryFinal);
		if (count == 1) {
			map.put(Constants.REPLAY, 1);
			map.put(Constants.MESSAGE, MSG_UPDATE_SUCCESS);
		} else {
			map.put(Constants.REPLAY, 0);
			map.put(Constants.MESSAGE, MSG_UPDATE_ERROR);
		}
		return map;
	}
	
	/**
	 * 修改工作组名称
	 */
	@RequestMapping(value = "/modifyWorkGroupName", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> modifyWorkGroupNamePost(String wgName, int paramId) {
		Map<String, Object> map = new HashMap<String, Object>();
		//重复名称验证
		boolean falg = paramService.isParamExist(wgName, Constants.WORK_GROUP);
		if(falg){
			map.put(Constants.REPLAY, 2);
			return map;
		}
		int count = paramService.updateParamNameById(paramId, wgName);
		if (count == 1) {
			map.put(Constants.REPLAY, 1);
			map.put(Constants.MESSAGE, MSG_UPDATE_SUCCESS);
		} else {
			map.put(Constants.REPLAY, 0);
			map.put(Constants.MESSAGE, MSG_UPDATE_ERROR);
		}
		return map;
	}
	
	/**
	 * 修改工作组状态是否启用
	 */
	@RequestMapping(value = "/modifyWorkGroupActivity", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> modifyWorkGroupActivityPost(int paramId) {
		Map<String, Object> map = new HashMap<String, Object>();
		boolean flag = paramService.changeParamActiveAndChangeUserStatusByParamId(paramId);
		if (flag) {
			map.put(Constants.REPLAY, 1);
		} else {
			map.put(Constants.REPLAY, 0);
		}
		return map;
	}
	
	/**
	 * 添加工作组信息
	 */
	@RequestMapping(value = "/addWorkGroupInfo", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> addWorkGroupInfoPost(String salary, String workGroupName) {
		Map<String, Object> map = new HashMap<String, Object>();
		//重复名称验证
		boolean falg = paramService.isParamExist(workGroupName, Constants.WORK_GROUP);
		if(falg){
			map.put(Constants.REPLAY, 2);
			return map;
		}
		//查询最大工作组编号
		String maxWorkGroupNumber = paramService.selectMaxParamValueByParamType(Constants.WORK_GROUP);
		//将string类型的工作组编号+1
		int mwgn = Integer.parseInt(maxWorkGroupNumber);
		String tempString = String.valueOf(mwgn+1);
		int tLenght = tempString.length();
		StringBuilder tempStringBuilder = new StringBuilder("");
		if(tLenght<6){
			for (int i = 0; i < 6-tLenght; i++) {
				tempStringBuilder.append("0");
			}
			tempStringBuilder.append(tempString);
		}
		//保存工作组信息 
		VtdParameter vp = new VtdParameter();
		vp.setParamName(workGroupName);
		vp.setParamValue(tempStringBuilder.toString());
		vp.setParamType("workGroup");
		vp.setIsActive(true);
		vp.setRemarks(salary);
		vp.setBackup1("unlock");
		vp.setBackup2("0");
		int count = paramService.saveParameter(vp);
		if (count == 1) {
			map.put(Constants.REPLAY, 1);
		} else {
			map.put(Constants.REPLAY, 0);
		}
		return map;
	}
	
	/**
	 * 修改支付宝支付是否启用
	 */
	@RequestMapping(value = "/changeAlipayStatus", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> changeAlipayStatusPost(int workerId,int alipayStatus) {
		Map<String, Object> map = new HashMap<String, Object>();
		int count = workerService.changeAlipayStatusByWorkerId(workerId,alipayStatus);
		if (count == 1) {
			map.put(Constants.REPLAY, 1);
		} else {
			map.put(Constants.REPLAY, 0);
		}
		return map;
	}
	
	/**
	 * 支付宝支付信息列表
	 */
	@RequestMapping(value = "/queryAlipayInfos", method = RequestMethod.GET)
	public ModelAndView queryAlipayInfosGet(int workerId, String beginDate, String endDate, int dateType, String realName) {
		Map<String, Object> model = new HashMap<>();
		String name="";
		try {
			name = new String(realName.getBytes("iso-8859-1"), "utf-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		model.put("workerId", workerId);
		model.put("beginDate", beginDate);
		model.put("endDate", endDate);
		model.put("dateType", dateType);
		model.put("realName", name);
		return new ModelAndView("manager/alipayInfoList", Constants.MODEL, model);
	}
	
	/**
	 * 工作者支付宝支付信息列表
	 */
	@RequestMapping(value = "/queryAlipayInfos", method = RequestMethod.POST)
	public Map<String, Object> queryAlipayInfosPost(int workerId, String beginDate, String endDate, int dateType, int page) {
		Map<String, Object> map = new HashMap<>();
		//查询支付信息数据
		List<AlipayInfo> alipayInfoList = alipayInfoService.queryAlipayInfoListByWorkerIdandPayDate(workerId,beginDate,endDate,dateType,page,Constants.ROW);
		List<Map<String,Object>> resultList = new ArrayList<Map<String,Object>>();
		double pageSalary = 0.0;
		for (AlipayInfo a : alipayInfoList) {
			if(a.getIsSuccess()){
				pageSalary = pageSalary+a.getAmount(); //计算当前页成功支付金额
			}
			Map<String,Object> result = new HashMap<String,Object>(); //装填页面显示用数据
			result.put("alipayId",a.getAlipayId()); 			
			result.put("alipayReturnCode",a.getAlipayReturnCode());   	
			result.put("alipayReturnMsg",a.getAlipayReturnMsg());		
			result.put("orderId",a.getOrderId());				
			result.put("outBizNo",a.getOutBizNo());				
			result.put("payDate",a.getPayDate());				
			result.put("subCode",a.getSubCode());				
			result.put("subMsg",a.getSubMsg());				
			result.put("payerRealName",a.getPayerRealName());		
			result.put("payeeRealName",a.getPayeeRealName());		
			result.put("payeeAccount",a.getPayeeAccount());		
			result.put("amount",a.getAmount());				
			result.put("isSuccess",a.getIsSuccess());          
			result.put("workerId",a.getWorkerId());  	
			DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			String dateString = df.format(a.getCreateDate());
			result.put("createDate",dateString);  
			resultList.add(result);
		}
		//查询总数
		int totle = alipayInfoService.queryAlipayInfoTotleByWorkerIdandPayDate(workerId,beginDate,endDate,dateType);
		double totleSalary = alipayInfoService.queryTotleSalaryByWorkerIdandPayDate(workerId,beginDate,endDate,dateType);
		int totlePage = (int) Math.ceil((double) totle / (double) Constants.ROW);
		map.put(Constants.TOTLE, totle);
		map.put(Constants.TOTLE_PAGE, totlePage);
		map.put("list", resultList);
		map.put("pageSalary", Math.round((pageSalary*100.0))/100.0);
		map.put("totleSalary", Math.round((totleSalary*100.0))/100.0);
		return map;
	}
	
	/**
	 * 根据支付信息查询任务
	 */
	@RequestMapping(value = "/queryWorkerRecordByOutBizNo", method = RequestMethod.GET)
	public ModelAndView queryWorkerRecordByOutBizNoGet(String outBizNo) {
		Map<String, Object> model = new HashMap<>();
		model.put("outBizNo", outBizNo);
		return new ModelAndView("manager/workerRecordList", Constants.MODEL, model);
	}
	
	/**
	 * 根据支付信息查询任务
	 */
	@RequestMapping(value = "/queryWorkerRecordByOutBizNo", method = RequestMethod.POST)
	public Map<String, Object> queryWorkerRecordByOutBizNoPost(String outBizNo) {
		Map<String, Object> map = new HashMap<>();
		List<workerRecord> list = workerRecordService.queryWorkerRecordByOutBizNo(outBizNo);
		map.put("list", list);
		return map;
	}
	
	/**
	 * 跳转到支付信息查询页面
	 */
	@RequestMapping(value = "/workerRecordSearch", method = RequestMethod.GET)
	public ModelAndView workerRecordSearchGet() {
		Map<String, Object> model = new HashMap<>();
		return new ModelAndView("manager/alipayWorkerRecordSearch", Constants.MODEL, model);
	}
	
	/**
	 * 支付宝支付列表
	 */
	@RequestMapping(value = "/queryAlipayList", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> queryAlipayListPost(String alipayAccount, String payeeRealName, int page, 
			String alipayBeginDate, String alipayEndDate, int alipayDateType, int alipayStatus) {
//		System.out.println(alipayAccount+"  "+payeeRealName+"  "+page+"  "+alipayBeginDate+"  "+alipayEndDate+"  "+alipayDateType+"  "+alipayStatus);
		
		if(alipayAccount.trim().length()==0){
			alipayAccount = null;
		}
		if(payeeRealName.trim().length()==0){
			payeeRealName = null;
		}
		Map<String, Object> map = new HashMap<>();
		//查询支付信息数据
		List<AlipayInfo> alipayInfoList = alipayInfoService.queryAlipayInfoList(alipayAccount,payeeRealName,alipayBeginDate,alipayEndDate,alipayDateType,alipayStatus,page,Constants.ROW,0);
		List<Map<String,Object>> resultList = new ArrayList<Map<String,Object>>();
		double pageSalary = 0.0;
		for (AlipayInfo a : alipayInfoList) {
			if(a.getIsSuccess()){
				pageSalary = pageSalary+a.getAmount(); //计算当前页成功支付金额
			}
			Map<String,Object> result = new HashMap<String,Object>(); //装填页面显示用数据
			result.put("alipayId",a.getAlipayId()); 			
			result.put("alipayReturnCode",a.getAlipayReturnCode());   	
			result.put("alipayReturnMsg",a.getAlipayReturnMsg());		
			result.put("orderId",a.getOrderId());				
			result.put("outBizNo",a.getOutBizNo());				
			result.put("payDate",a.getPayDate());				
			result.put("subCode",a.getSubCode());				
			result.put("subMsg",a.getSubMsg());				
			result.put("payerRealName",a.getPayerRealName());		
			result.put("payeeRealName",a.getPayeeRealName());		
			result.put("payeeAccount",a.getPayeeAccount());		
			result.put("amount",a.getAmount());				
			result.put("isSuccess",a.getIsSuccess());          
			result.put("workerId",a.getWorkerId());  	
			DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			String dateString = df.format(a.getCreateDate());
			result.put("createDate",dateString);  
			resultList.add(result);
		}
		//查询总数
		int totle = alipayInfoService.queryAlipayInfoTotle(alipayAccount,payeeRealName,alipayBeginDate,alipayEndDate,alipayDateType,alipayStatus,page,Constants.ROW,0);
		double totleSalary = alipayInfoService.queryTotleSalary(alipayAccount,payeeRealName,alipayBeginDate,alipayEndDate,alipayDateType,page,Constants.ROW,0);
		int totlePage = (int) Math.ceil((double) totle / (double) Constants.ROW);
		map.put(Constants.TOTLE, totle);
		map.put(Constants.TOTLE_PAGE, totlePage);
		map.put("list", resultList);
		map.put("pageSalary", Math.round((pageSalary*100.0))/100.0);
		map.put("totleSalary", Math.round((totleSalary*100.0))/100.0);
		return map;
	}
	
	/**
	 * 持有任务数查询
	 */
	@RequestMapping(value = "/queryNotReturnNums", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> queryNotReturnNumPost() {
		Map<String, Object> map = new HashMap<String, Object>();
		List<Map<String, Object>> result = workerRecordService.queryNotReturnNums();
		map.put(Constants.REPLAY, 1);
		map.put("result", result);
		return map;
	}
	/**
	 * 设置新的外包商 修改外包商代码
	 */
	@RequestMapping(value = "/outsourcerSetting", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> outsourcerSetting(String tempOutsourcerCodes) {
		Map<String, Object> map = new HashMap<String, Object>();
		int lastIndex = tempOutsourcerCodes.lastIndexOf(",");
		String outsourcerCodes = tempOutsourcerCodes.substring(0, lastIndex);
		List<VtdParameter> outsourcerCodeList = paramService.selectParamByType(Constants.OUTSOURCER_CODES);  //外包商组代码  数据库中只存一条信息  	
		VtdParameter param = outsourcerCodeList.get(0);
		int num = paramService.updateParamValueById(param.getId(), outsourcerCodes);
		if(num==1){
			map.put(Constants.REPLAY, 1);
		}else{
			map.put(Constants.REPLAY, 0);
		}
		return map;
	}
	
	/**
	 * 增加通知公告
	 * 
	 * @param title
	 * @param content
	 * @return
	 */
	@RequestMapping(value = "/addNotice", method = RequestMethod.POST)
	@ResponseBody
	public  Map<String, Object> addNoticePOST(String title, String content, HttpSession session) {
		Map<String, Object> map = new HashMap<>();
		VtdNotice notice = new VtdNotice();
		notice.setNoticeTitle(title);
		notice.setNoticeContent(content);
		notice.setCreateId(Integer.parseInt(session.getAttribute(Constants.USER_ID).toString()));
		notice.setCreateTime(new Date());
		notice.setUpdateTime(new Date());
		int num = noticeService.addNoticeAndSend(notice);
		if(num==1){
			map.put(Constants.REPLAY, 1);
			map.put(Constants.MESSAGE, "新增成功,并提醒用户查看!");
		}else{
			map.put(Constants.REPLAY, 0);
			map.put(Constants.MESSAGE, "新增失败,请联系系统维护人员!");
		}
		return map;
	}
	
	/**
	 * 跳转到通知公告列表页
	 */
	@RequestMapping(value = "/noticeList", method = RequestMethod.GET)
	public ModelAndView noticeListGET() {
		return new ModelAndView(Constants.MANAGER + Constants.SLASH + "noticeList");
	}
	
	/**
	 * 查询通知公告列表
	 */
	@RequestMapping(value = "/noticeList", method = RequestMethod.POST)
	@ResponseBody
	public  Map<String, Object> noticeListPOST(String condition, int page) {
		logger.debug("condition:{}", condition);
		Map<String, Object> map = new HashMap<String, Object>();
		List<Map<String,Object>> result = new ArrayList<>();
		List<VtdNotice> noticeList = noticeService.getAllNoticeOrderByUpdateTimeDesc(condition, page, Constants.ROW);
		SimpleDateFormat sdf = new SimpleDateFormat(Constants.DATETIME_FORMAT);		
		for (VtdNotice notice : noticeList) {
			Map<String,Object> temp = new HashMap<String,Object>();
			temp.put("id", notice.getId());
			temp.put("noticeTitle", notice.getNoticeTitle());
			temp.put("createTime", sdf.format(notice.getCreateTime()));
			temp.put("updateTime", sdf.format(notice.getUpdateTime()));
			result.add(temp);
		}
		int totle = noticeService.getAllNoticeOrderByUpdateTimeDescCount(condition);
		map.put(Constants.LIST, result);
		map.put(Constants.TOTLE, totle);
		map.put(Constants.TOTLE_PAGE, Math.ceil((double) totle / (double) Constants.ROW));
		return map;
	}
	
	/**
	 * 查看通知公告内容
	 * 
	 * @return
	 */
	@RequestMapping(value = "/showNoticeContent", method = RequestMethod.GET)
	public  ModelAndView showNoticeContent(int id) {
		VtdNotice notice = noticeService.selectById(id);
		return new ModelAndView(Constants.MANAGER + Constants.SLASH + "showNotice", "notice", notice);
	}
	
	/**
	 * 编辑通知公告内容
	 * 
	 * @return
	 */
	@RequestMapping(value = "/editNoticeContent", method = RequestMethod.GET)
	public  ModelAndView editNoticeContent(int id) {
		VtdNotice notice = noticeService.selectById(id);
		return new ModelAndView(Constants.MANAGER + Constants.SLASH + "editNotice", "notice", notice);
	}
	
	/**
	 * 更新通知公告
	 * @param title
	 * @param content
	 * @return
	 */
	@RequestMapping(value = "/updateNotice", method = RequestMethod.POST)
	@ResponseBody
	public  Map<String, Object> updateNotice(int id, String title, String content, HttpSession session) {
		Map<String, Object> map = new HashMap<>();
		VtdNotice notice = new VtdNotice();
		notice.setId(id);
		notice.setNoticeTitle(title);
		notice.setNoticeContent(content);
		notice.setUpdateId(Integer.parseInt(session.getAttribute(Constants.USER_ID).toString()));
		notice.setUpdateTime(new Date());
		int num = noticeService.updateNoticeById(notice);
		if(num == 1){
			map.put(Constants.REPLAY, 1);
			map.put(Constants.MESSAGE,MSG_UPDATE_SUCCESS);
		}else{
			map.put(Constants.REPLAY, 0);
			map.put(Constants.MESSAGE,"更新失败,请联系系统维护人员!");
		}
		return map;
	}
	
	/**
	 * 发布通知公告  系统提示的通知只显示最新增加或更新的一条
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/noticeSend", method = RequestMethod.POST)
	@ResponseBody 
	public   Map<String, Object> noticeSend() {
		Map<String, Object> map = new HashMap<>();
		int num = noticeService.noticeSend();
		if(num>0){
			map.put(Constants.REPLAY, 1);
			map.put(Constants.MESSAGE, "提醒信息已发送!");
		}else{
			map.put(Constants.REPLAY, 0);
			map.put(Constants.MESSAGE, "提醒信息发送失败,请联系系统维护人员!");
		}
		return map;
	}
	
	/**
	 * 通知公告不在显示提示信息
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/noticeNeverReceive", method = RequestMethod.POST)
	@ResponseBody 
	public   Map<String, Object> noticeNeverReceive(HttpSession session) {
		Map<String, Object> map = new HashMap<>();
		String userId = session.getAttribute(Constants.USER_ID).toString();
		int num = noticeService.neverReceiveByUserId(Integer.parseInt(userId));
		session.setAttribute(Constants.NOTICE_FLAG, 0);
		if(num==1){
			map.put(Constants.REPLAY, 1);
		}else{
			map.put(Constants.REPLAY, 0);
		}
		return map;
	}
	
	/**
	 * 修改真实姓名
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/editRealName", method = RequestMethod.POST)
	@ResponseBody 
	public   Map<String, Object> editRealName(int userId, String newRealName) {
		Map<String, Object> map = new HashMap<>();
		worker w1 = workerService.getWorkerByUserId(userId);
		int num = workerService.editRealNameByWorkerId(newRealName,w1.getWorkerId());
		if(num==1){
			map.put(Constants.REPLAY, 1);
		}else{
			map.put(Constants.REPLAY, 0);
		}
		return map;
	}
	
	
	/**
	 * 获得所有可使用的工作组返回给前台select
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/getWorkGroups", method = RequestMethod.POST)
	@ResponseBody 
	public   Map<String, Object> getWorkGroups(int userId) {
		Map<String, Object> map = new HashMap<>();
		user user = userService.getByPrimaryKey(userId);
		map.put("workGroupCode", user.getWorkGroupCode());
		List<VtdParameter> list = paramService.selectParamByType(Constants.WORK_GROUP);
		List<Map<String,String>> result = new ArrayList<Map<String,String>>();
		for (VtdParameter param : list) {
			Map<String,String> m = new HashMap<String,String>();
			m.put("value", param.getParamValue());
			m.put("name", param.getParamName());
			result.add(m);
		}
		map.put("list", result);
		return map;
	}
	
	/**
	 * 修改工作组用户组
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/changeWorkGroup", method = RequestMethod.POST)
	@ResponseBody 
	public   Map<String, Object> changeWorkGroup(HttpSession session, String workGroupCode, int userId) {
		Map<String, Object> map = new HashMap<>();
		int operatorId = Integer.parseInt(session.getAttribute(Constants.USER_ID).toString());
		int num = userService.changeWorkGroupByUserId(userId,workGroupCode,operatorId);
		if(num==2){
			map.put("msg", "更新成功!");
		}else{
			map.put("msg", "更新工作组信息时出现问题, 请联系系统维护人员!");
		}
		return map;
	}
	
	/**
	 * 修改工作组工资
	 */
	@RequestMapping(value = "/modifyOneLayerSubsidy", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> modifyOneLayerSubsidyPost(String subsidy, int paramId) {
		Map<String, Object> map = new HashMap<String, Object>();
		Double subsidyFinal = Double.parseDouble(subsidy)/100;
		int count = paramService.updateBackup2ById(paramId, subsidyFinal.toString());
		if (count == 1) {
			map.put(Constants.REPLAY, 1);
			map.put(Constants.MESSAGE, MSG_UPDATE_SUCCESS);
		} else {
			map.put(Constants.REPLAY, 0);
			map.put(Constants.MESSAGE, MSG_UPDATE_ERROR);
		}
		return map;
	}
	
    /**
     * 定时器  剩余的可下载地任务数预警
     * 记录平台可下载任务  已下载任务  已上传任务 已审核任务数  提供任务不够的预警
     */
	//@RequestMapping(value = "/sssaaa", method = RequestMethod.GET)  //测试用请求地址
	@Scheduled(cron="0 00 1 * * ?")    
    public void remainingDownloadableTaskNumberWarn(){
    	logger.error("定时器: 剩余的可下载地任务数预警  ERROR是自己定的级别线上应该只显示ERROR的log");
    	//处理时间为当前时间的前一天
    	Calendar calendar = Calendar.getInstance();	 //此时打印它获取的是系统当前时间
    	calendar.add(Calendar.DATE, -1);    //得到前一天
    	String  yestedayDate = new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime());
    	//查询全部可下载任务数  
    	int downloadableTaskNumber = taskService.getCountTaskDoing(9);//查询全部可下载任务数
    	//当天已上传任务数    
    	int uploadCount = workerRecordService.queryUploadCountByDate(yestedayDate);
    	// 对算剩余天数 = 全部剩余数 除以 当天上传数 
    	String remainMessage;
    	String days;
    	if(uploadCount==0){
    		days = "-";
    		remainMessage = "前一天上传总数为0, 剩余天数无法计算!";
    	}else{
    		DecimalFormat df = new DecimalFormat("0.00");
    		days = df.format((double)downloadableTaskNumber/uploadCount);
    		remainMessage = "当前可下载任务数:"+downloadableTaskNumber+" 前一天总上传任务数量:"+uploadCount+"  预计在"+days+"天后任务将会被做完!";
    	}
    	// 根据剩余天数设置预警信息级别   
    	int warningLevel;
    	if((double)downloadableTaskNumber/uploadCount<=3){
    		warningLevel = 1;
    	}else if((double)downloadableTaskNumber/uploadCount>3&&(double)downloadableTaskNumber/uploadCount<=5){
    		warningLevel = 2;
    	}else{
    		warningLevel = 3;
    	}
    	
    	RemainingTaskWarning rtw = new RemainingTaskWarning();
    	rtw.setId(UUID.randomUUID().toString().replace("-", "").toUpperCase());
    	rtw.setDownloadableTaskNumber(downloadableTaskNumber);
    	rtw.setUploadCount(uploadCount);
    	rtw.setQueryDate(yestedayDate);
    	rtw.setRemainDays(days);
    	rtw.setRemainMessage(remainMessage);
    	rtw.setWarningLevel(warningLevel);
    	rtw.setCreateDate(new Date());
    	int count = rtwService.save(rtw);
    	if(count!=1){
    		logger.error("定时器: 剩余的可下载地任务数预警  警告信息存入数据库出错");
    	}
    	
    	//编辑邮件内容
    	StringBuilder sb = new StringBuilder();
		sb.append(remainMessage);
		sb.append("<br/>");
		sb.append("<br/>");
		sb.append("本邮件为系统自动发出请不要回复谢谢！");
		String title = "语音标注平台剩余任务预警";
    	// 剩余5天开始提示给管理员发邮件  剩余3天扩大邮件范围  页面给管理员弹提示框 改变背景颜色
    	if(warningLevel<3){
    		RemainingTaskWarningMailSender m = new RemainingTaskWarningMailSender();
    		try {
    			m.sendMail(sb.toString(),title,warningLevel);
    		} catch (MessagingException e) {
    			e.printStackTrace();
    			logger.error("邮件发送出错！！！" );
    		} catch (GeneralSecurityException e) {
    			e.printStackTrace();
    			logger.error("邮件发送出错！！！" );
    		}		
    	}
	}
	
	/**
	 * 工作组详细工资列表信息
	 * 
	 * @param userId
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/workGroupUploadTimeDetails", method = RequestMethod.GET)
	public ModelAndView workGroupUploadTimeDetails(String workGroupCode, HttpServletRequest request) {
		Map<String, Object> model = new HashMap<>();
		String dateType = request.getParameter("dateType");
		String beginDate = request.getParameter("beginDate");
		String endDate = request.getParameter("endDate");
		try {
			String workGroupName = new String(request.getParameter("workGroupName").getBytes("iso-8859-1"), "utf-8");
			model.clear();
			model.put("workGroupCode", workGroupCode);
			model.put("workGroupName", workGroupName);
			model.put("dateType", dateType);
			model.put("beginDate", beginDate);
			model.put("endDate", endDate);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return new ModelAndView("manager/workGroupUploadTimeList", Constants.MODEL, model);

	}
	
	/**
	 * 查询工作者已上传时间
	 * @param userNameCondition
	 * @param beginDate
	 * @param endDate
	 * @param dateType
	 * @param workGroupCode
	 * @return
	 */
	@RequestMapping(value = "/workerUploadTime", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> workerUploadTime(String userNameCondition, String beginDate, String endDate, int dateType, String workGroupCode) {
		Map<String, Object> map = new HashMap<String, Object>();
		List<Map<String, Object>> list = workerRecordService.getWorkerUploadTime(dateType, beginDate, endDate, userNameCondition, workGroupCode);
		if (list == null) {
			map.put(Constants.LIST, "");
			return map;
		}
		map.put(Constants.LIST, list);
		return map;
	}
	
	/**
	 * 修改任务的回传时间  再原基础上进行增加
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/changeAllLockTime", method = RequestMethod.POST)
	@ResponseBody 
	public   Map<String, Object> changeAllLockTime(HttpSession session, int userId, int day) {
		Map<String, Object> map = new HashMap<>();
		worker worker = workerService.getWorkerByUserId(userId);
		int workerId = worker.getWorkerId();
		//查询工作者下载任务数
		int count = workerRecordService.getWorkerDownloadTaskNumByWorkerId(workerId);
		if(count==0){
			map.put("msg", "没有查询到可调整时限的数据!");
			return map;
		}
		//修改数据
		long lockTime = day*24*3600*1000L;
		int updateNum = workerRecordService.changeWorkerDownloadTaskLockTimeByWorkerId(workerId, lockTime);
		if(updateNum>0){
			map.put("msg", "更新成功! 更新了"+updateNum+"个任务的时限!");
		}else{
			map.put("msg", "更新工作组信息时出现问题, 请联系系统维护人员!");
		}
		return map;
	}
	
	/**
	 * 查询审核的有效标注时间记录
	 * @param beginDate
	 * @param endDate
	 * @param dateType
	 * @return
	 */
	@RequestMapping(value = "/queryInspectionMarkTimeRecords", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> queryInspectionMarkTimeRecords(String beginDate, String endDate, int dateType) {
		Map<String, Object> map = new HashMap<String, Object>();
		SimpleDateFormat sdf = new SimpleDateFormat(Constants.DATETIME_FORMAT);
		List<Map<String, String>> resultList = new ArrayList<Map<String, String>>(); 
		//前台的查询条件
		Map<String,Object> conditions = new HashMap<String, Object>();
		conditions.put("beginDate", beginDate);
		conditions.put("endDate", endDate);
		conditions.put("dateType", dateType);
		//查询显示用list
		List<Map<String, Object>> list = imtrService.queryInspectionMarkTimeRecordListByConditions(conditions);
		//处理页面显示用的信息
		if(!list.isEmpty()){
			for (Map<String, Object> m : list) {
				Map<String,String> tempMap = new HashMap<String, String>();
				tempMap.put("inspectorId", m.get("inspectorId").toString());
				tempMap.put("inspectorName", m.get("inspectorName").toString());
				String qualifiedMarkTime = String.valueOf((double)m.get("qualifiedMarkTime")/3600);
				String unqualifiedMarkTime = String.valueOf((double)m.get("unqualifiedMarkTime")/3600);
				String total = String.valueOf((double)m.get("total")/3600);
				tempMap.put("qualifiedMarkTime", qualifiedMarkTime);
				tempMap.put("unqualifiedMarkTime" , unqualifiedMarkTime);
				tempMap.put("total", total);
				tempMap.put("qualifiedMarkTimeSec", m.get("qualifiedMarkTime").toString());
				tempMap.put("unqualifiedMarkTimeSec" ,m.get("unqualifiedMarkTime").toString());
				tempMap.put("totalSec", m.get("total").toString());
				if(m.get("userType").toString().equals("3")){
					tempMap.put("userType", "初审");
				}else{
					tempMap.put("userType", "巡审");
				}
				tempMap.put("userName", m.get("userName").toString());
				resultList.add(tempMap);
			}
		}else{
			resultList = null;
		}
		map.put("list", resultList);
		return map;
	}
}
